package com.oracle.application.config;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.oracle.application.entity.Paylog;
import com.oracle.application.entity.vo.PayVo;
import com.oracle.application.feign.OrderFeign;
import com.oracle.application.service.IPaylogService;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @author bug制造者
 * @ClassName PayConfig.java
 * @createTime 2021年07月06日 15:16:00
 * @Description
 */
@Data
@Component
@ConfigurationProperties(prefix = "payconfig")
public class PayConfig {

    private String app_id;
    private String payGateway;
    private String notify_url;
    private String return_url;
    private String publicKey;
    private String privateKey;

    @Autowired
    private IPaylogService iPaylogService;

    @Autowired
    private OrderFeign orderFeign;

    public String doPay(PayVo payVo,Integer orderId){
        //1、根据支付宝的配置生成一个支付客户端
        AlipayClient alipayClient = new DefaultAlipayClient(payGateway, app_id, privateKey, "json", "utf-8", publicKey, "RSA2");
        //2、创建一个支付请求 //设置请求参数
        AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
        request.setNotifyUrl(notify_url);
        request.setReturnUrl(return_url);

        Paylog paylog = new Paylog();
        paylog.setCreatedate(LocalDateTime.now()); //设置创建时间
        paylog.setModifydate(LocalDateTime.now()); //设置修改时间

        return "";
    }

}
